package org.chen.controller;

import lombok.RequiredArgsConstructor;
import org.chen.common.domain.R;
import org.chen.domain.vo.DashboardVO;
import org.chen.service.DashboardService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/dashboard")
@RequiredArgsConstructor
public class DashboardController {

    private final DashboardService dashboardService;

    @GetMapping
    public DashboardVO getDashboardData() {
//        DashboardVO dashboardData = dashboardService.getDashboardData();
//        System.out.println("获取getDashboardData响应值：" + dashboardData);
        return dashboardService.getDashboardData();
    }

    @GetMapping("/days")
    public R<DashboardVO> getDashboardDataByDays(
            @RequestParam(defaultValue = "7") int days) {
//        DashboardVO dashboardDataByDays = dashboardService.getDashboardDataByDays(days);
//        System.out.println("获取getDashboardDataByDays响应值：" + dashboardDataByDays);
        return R.success(dashboardService.getDashboardDataByDays(days));
    }

    @PostMapping("/refresh")
    public R<Void> refreshStatisticsCache() {
        dashboardService.refreshStatisticsCache();
        return R.success();
    }
}